package com.orange.score.activity.entry;

import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.text.Editable;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TableRow.LayoutParams;
import com.orange.score.activity.common.CommonFootballActivity;
import com.orange.score.activity.repository.RepositorySelectLeagueActivity;
import com.orange.score.app.ScoreApplication;
import com.orange.score.constants.FilterContinentType;
import com.orange.score.model.repository.Country;
import com.orange.score.model.repository.RepositoryManager;
import com.orange.score.network.ResultCodeType;
import com.orange.score.service.RepositoryService;
import com.orange.score.service.RepositoryServiceCallBack;
import java.util.List;

public class RepositoryActivity extends CommonFootballActivity
  implements RepositoryServiceCallBack
{
  private static int DEFAULT_COLUMN;
  private static String TAG = RepositoryActivity.class.getName();
  private Button[] buttons;
  RepositoryManager repositoryManager;
  Button searchButton;
  EditText searchTxt;
  private TableLayout tableLayout;

  static
  {
    DEFAULT_COLUMN = 4;
  }

  private void buildTableLayout(List<Country> paramList, int paramInt)
  {
    int j;
    int k;
    TableRow localTableRow;
    TableRow.LayoutParams localLayoutParams;
    int l;
    if (paramList == null)
      return;
    int i = paramList.size();
    if (i % DEFAULT_COLUMN == 0)
      j = i / DEFAULT_COLUMN;
    while (true)
    {
      this.buttons = new Button[j * DEFAULT_COLUMN];
      k = 0;
      while (true)
      {
        if (k >= j);
        localTableRow = new TableRow(this);
        localLayoutParams = new TableRow.LayoutParams(-2, -2, 1F);
        localLayoutParams.width = 1;
        localLayoutParams.setMargins(5, 5, 5, 5);
        this.tableLayout.setLayoutParams(localLayoutParams);
        l = 0;
        if (l < paramInt)
          break label134;
        this.tableLayout.addView(localTableRow);
        ++k;
      }
      j = 1 + i / DEFAULT_COLUMN;
    }
    label134: int i1 = l + k * DEFAULT_COLUMN;
    this.buttons[i1] = new Button(this);
    if (i1 >= i)
    {
      this.buttons[i1].setLayoutParams(localLayoutParams);
      localTableRow.addView(this.buttons[i1]);
      this.buttons[i1].setVisibility(4);
    }
    while (true)
    {
      while (true)
        ++l;
      Country localCountry = (Country)paramList.get(i1);
      this.buttons[i1].setText(localCountry.getCountryName());
      this.buttons[i1].setTextColor(getResources().getColor(2131230754));
      this.buttons[i1].setLayoutParams(localLayoutParams);
      this.buttons[i1].setSingleLine();
      this.buttons[i1].setTextSize(12.0F);
      this.buttons[i1].setBackgroundResource(2130837640);
      this.buttons[i1].setHeight(33);
      localTableRow.addView(this.buttons[i1]);
      setCountrySelectedButtonClickListener(this.buttons[i1], localCountry.getCountryId(), localCountry.getCountryName());
    }
  }

  private RepositoryManager getRepositoryManager()
  {
    return getRepositoryService().getRepositoryManager();
  }

  private RepositoryService getRepositoryService()
  {
    return ((ScoreApplication)getApplication()).getRepositoryService();
  }

  private void removeTableLayout()
  {
    this.tableLayout.removeAllViewsInLayout();
  }

  private void setContinentFilterButtonClickListener(int paramInt, FilterContinentType paramFilterContinentType)
  {
    ((Button)findViewById(paramInt)).setOnClickListener(new View.OnClickListener(this, paramFilterContinentType)
    {
      public void onClick()
      {
        RepositoryManager localRepositoryManager = RepositoryActivity.access$0(this.this$0);
        localRepositoryManager.setFilterContinent(this.val$whichContinent);
        List localList = localRepositoryManager.filterCountry();
        this.this$0.updateCountryList(localList);
        RepositoryActivity.access$1(this.this$0);
      }
    });
  }

  private void setCountrySelectedButtonClickListener(Button paramButton, String paramString1, String paramString2)
  {
    paramButton.setOnLongClickListener(new View.OnLongClickListener(this, paramButton)
    {
      public boolean onLongClick()
      {
        this.val$button.setTextColor(-1);
        return false;
      }
    });
    paramButton.setOnClickListener(new View.OnClickListener(this, paramButton, paramString1, paramString2)
    {
      public void onClick()
      {
        this.val$button.setTextColor(-1);
        Intent localIntent = new Intent();
        localIntent.setClass(this.this$0, RepositorySelectLeagueActivity.class);
        Bundle localBundle = new Bundle();
        localBundle.putString("countryId", this.val$countryId);
        localBundle.putString("countryName", this.val$countryName);
        localIntent.putExtras(localBundle);
        this.this$0.startActivity(localIntent);
      }
    });
  }

  private void setSearchButtonClickListener()
  {
    this.searchButton.setOnClickListener(new View.OnClickListener(this)
    {
      public void onClick()
      {
        String str = this.this$0.searchTxt.getText().toString();
        Intent localIntent = new Intent();
        localIntent.setClass(this.this$0, RepositorySelectLeagueActivity.class);
        Bundle localBundle = new Bundle();
        localBundle.putString("key", str);
        localIntent.putExtras(localBundle);
        this.this$0.startActivity(localIntent);
      }
    });
  }

  private void updateContinentFilterButton()
  {
    int[] arrayOfInt;
    int j;
    int i = 2131558557;
    FilterContinentType localFilterContinentType = this.repositoryManager.getFilterContinent();
    switch ($SWITCH_TABLE$com$orange$score$constants$FilterContinentType()[localFilterContinentType.ordinal()])
    {
    default:
    case 1:
    case 2:
    case 3:
    case 4:
    case 6:
    case 5:
    }
    while (true)
    {
      while (true)
      {
        while (true)
        {
          while (true)
          {
            while (true)
            {
              while (true)
              {
                arrayOfInt = new int[6];
                arrayOfInt[0] = 2131558610;
                arrayOfInt[1] = 2131558611;
                arrayOfInt[2] = 2131558612;
                arrayOfInt[3] = 2131558613;
                arrayOfInt[4] = 2131558614;
                arrayOfInt[5] = 2131558615;
                j = 0;
                if (j < arrayOfInt.length)
                  break label138;
                return;
                i = 2131558610;
              }
              i = 2131558611;
            }
            i = 2131558612;
          }
          i = 2131558613;
        }
        i = 2131558614;
      }
      i = 2131558615;
    }
    label138: Button localButton = (Button)findViewById(arrayOfInt[j]);
    if (arrayOfInt[j] == i)
      localButton.setSelected(true);
    while (true)
    {
      while (true)
        ++j;
      localButton.setSelected(false);
    }
  }

  public void loadAllRepositoryFinish(ResultCodeType paramResultCodeType)
  {
    buildTableLayout(this.repositoryManager.filterCountry(), DEFAULT_COLUMN);
  }

  public void loadGroupInfoFinish(ResultCodeType paramResultCodeType)
  {
  }

  public void loadRoundInfoFinish(ResultCodeType paramResultCodeType)
  {
  }

  public void onBackPressed()
  {
    super.onBackPressed();
  }

  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    setContentView(2130903094);
    setContinentFilterButtonClickListener(2131558610, FilterContinentType.INTERNATION);
    setContinentFilterButtonClickListener(2131558611, FilterContinentType.EUROPE);
    setContinentFilterButtonClickListener(2131558612, FilterContinentType.AMERICA);
    setContinentFilterButtonClickListener(2131558613, FilterContinentType.ASIA);
    setContinentFilterButtonClickListener(2131558614, FilterContinentType.AFRICA);
    setContinentFilterButtonClickListener(2131558615, FilterContinentType.OCEANIA);
    this.searchButton = ((Button)findViewById(2131558608));
    this.searchTxt = ((EditText)findViewById(2131558607));
    setSearchButtonClickListener();
    this.tableLayout = ((TableLayout)findViewById(2131558617));
    this.tableLayout.setStretchAllColumns(true);
  }

  protected void onPause()
  {
    super.onPause();
    ScoreApplication.currentActivity = null;
  }

  public void onRefresh()
  {
    removeTableLayout();
    getRepositoryService().loadRepository(this, this);
  }

  protected void onResume()
  {
    int i;
    super.onResume();
    removeTableLayout();
    getRepositoryService().loadRepository(this, this);
    this.repositoryManager = getRepositoryManager();
    updateContinentFilterButton();
    ScoreApplication.currentActivity = this;
    if ((this.buttons != null) && (this.buttons.length > 0))
      i = 0;
    while (true)
    {
      if (i >= this.buttons.length)
        return;
      if (this.buttons[i] != null)
        this.buttons[i].setTextColor(getResources().getColor(2131230754));
      ++i;
    }
  }

  protected void updateCountryList(List<Country> paramList)
  {
    removeTableLayout();
    buildTableLayout(this.repositoryManager.filterCountry(), DEFAULT_COLUMN);
  }
}